<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\OpinionType;
use app\common\model\UserOpinion;
use fast\Random;
use think\Config;
use think\Exception;
use think\Validate;

/**
 * 反馈接口
 */
class Opinions extends Api
{
    protected $noNeedLogin = [''];
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * 反馈类型
     */
    public function type(){
        $list = OpinionType::order('id desc')->paginate();

        $this->success(__('Get success'),$list);
    }

    /**
     * 创建反馈
     */
    public function create(){
        $params = $this->request->post();
        $validate = new \app\api\validate\Opinions();
        if(!$validate->scene('add')->check($params)){
            $this->error(__($validate->getError()));
        }

        $data = [
            'user_id'   => $this->auth->id,
            'type_id'   => $params['type_id'],
            'username'  => $params['username'],
            'mobile'    => $params['mobile'],
            'content'   => $params['content'],
        ];

        UserOpinion::create($data);

        $this->success(__('Operation completed'));
    }
}